#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
LL y,z,p;
map<LL,LL>tab;
LL gcd(LL a,LL b)
{
	return b?gcd(b,a%b):a;
}
LL qpow(LL a,LL b,LL MOD)
{
	LL ans=1;
	for(;b;b>>=1,a=a*a%MOD)
		if(b&1)ans=ans*a%MOD;
	return ans;
}
LL exBSGS(LL y,LL z,LL p)
{
	y%=p;z%=p;
	tab.clear();
	if(!y)
	{
		if(!z)return 1;
		return -1;
	}
	else if(z==1)return 0;
	LL t,cnt=0,d=1;
	while((t=gcd(y,p))!=1)
	{
		if(z%t)return -1;
		++cnt,z/=t,p/=t,d=d*(y/t)%p;
		if(z==d)return cnt;
	}
	LL m=ceil(sqrt(p));
	LL k=z%p;t=qpow(y,m,p);
	tab[z]=m;
	for(LL j=1;j<m;++j)
	{
		k=k*y%p;
		tab[k]=j;
	}
	for(LL i=1;i<=m+1;++i)
	{
		d=d*t%p;
		if(tab[d])return i*m-(tab[d]%m)+cnt;
	}
	return -1;
}
int main()
{
	while(~scanf("%lld%lld%lld",&y,&p,&z))
	{
		if(!y&&!z&&!p)break;
		LL ans=exBSGS(y,z,p);
		if(~ans)printf("%lld\n",ans);
		else puts("No Solution");
	}
	return 0;
}
